from ..extensions import db
from datetime import datetime

class DeviceInfo(db.Model):
    # 设备信息
    __tablename__ = "device_info"
    id            = db.Column(db.Integer, primary_key=True)
    Node          = db.Column(db.String(50), default='Default')
    SubNode       = db.Column(db.String(50), default='Default')
    DevGroup      = db.Column(db.String(50), default='Default')
    DevIp         = db.Column(db.String(50), unique=True, index=True)
    DevName       = db.Column(db.String(50))
    DevIPv6       = db.Column(db.String(50))
    DevIpmi       = db.Column(db.String(50))
    DevNote       = db.Column(db.Text(50), default='None')
    timestamp     = db.Column(db.DateTime, default=datetime.utcnow)

    def get_info(self):
        data = {'id': self.id, 'DevGroup': self.DevGroup, 'DevIp': self.DevIp, 'DevName': self.DevName,
                'DevIPv6': self.DevIPv6, 'DevIpmi': self.DevIpmi, 'DevNote': self.DevNote}
        return data

class DevLoginInfo(db.Model):
    # 设备登录信息
    __tablename__ = "dev_login_info"
    id            = db.Column(db.Integer, primary_key=True)
    DevIp         = db.Column(db.String(50), unique=True)
    Port          = db.Column(db.String(50))
    User          = db.Column(db.String(50))
    UserPWD       = db.Column(db.String(50))
    RootPWD       = db.Column(db.String(50))
    DevLoginNote  = db.Column(db.Text(50), default='None')
    timestamp     = db.Column(db.DateTime, default=datetime.utcnow)

    def get_info(self):
        data = {'id': self.id, 'DevIp': self.DevIp, 'Port': self.Port, 'User': self.User, 
                'UserPWD': self.UserPWD, 'RootPWD': self.RootPWD, 'DevLoginNote': self.DevLoginNote}
        return data
